Attribute VB_Name = "Mod_Detalle"
Option Explicit
Public wjCodigo As String
Dim Col As TrueOleDBGrid80.Column
Dim cols As TrueOleDBGrid80.Columns

'enum para form fAbcDetProvisionSinOc
Public Enum eParentProvision
    icParentProvicion = 1
    icParentRendicion = 2
End Enum


Public Sub LimpiarFiltro(Ado As Adodc, Grilla As TrueOleDBGrid80.TDBGrid)
    For Each Col In Grilla.Columns
        Col.FilterText = ""
    Next Col
End Sub

Public Sub Buscar_TruedbGrilla(dc As Adodc, Nombre As TrueOleDBGrid80.TDBGrid)
On Error GoTo ErrHandler
    Dim c As Integer
    With Nombre
        Set cols = .Columns
        c = .Col
       .HoldFields
       dc.Recordset.Filter = GetFilter()
       .Col = c
       .EditActive = True
     End With
     Exit Sub
ErrHandler:
    MsgBox Err.Source & ":" & vbCrLf & Err.Description
End Sub

Public Function GetFilter() As String
    Dim tmp As String
    Dim N As Integer
    For Each Col In cols
        If Trim(Col.FilterText) <> "" Then
            N = N + 1
            If N > 1 Then
                tmp = tmp & " AND "
            End If
            tmp = tmp & Col.DataField & " LIKE '" & Col.FilterText & "*'"
        End If
    Next Col
    GetFilter = tmp
End Function

Public Sub Limpia_Controls(F As Form, Clase As String)
On Error GoTo Mensaje
    Dim Nc As Integer, i As Integer
    Nc = F.Controls.Count - 1
    For i = 0 To Nc
        If (TypeName(F.Controls(i)) = Clase) Then
            F.Controls(i).Text = ""
        End If
    Next i
    Exit Sub
Mensaje:
    MsgBox Err.Description, vbInformation + vbCritical
End Sub

Public Sub BackColores_Controls(F As Form, Clase As String, xtColor As String)
On Error GoTo Mensaje
    Dim Nc As Integer, i As Integer
    Nc = F.Controls.Count - 1
    For i = 0 To Nc
        If (TypeName(F.Controls(i)) = Clase) Then
            F.Controls(i).BackColor = xtColor
        End If
    Next i
    Exit Sub
Mensaje:
    MsgBox Err.Description, vbInformation + vbCritical
End Sub

Public Sub Habilitar_Controles(F As Form, Clase As String, Valor As Boolean)
On Error GoTo Mensaje
    Dim Nc As Integer, i As Integer
    Nc = F.Controls.Count - 1
    For i = 0 To Nc
        If (TypeName(F.Controls(i)) = Clase) Then
            F.Controls(i).Enabled = Valor
        End If
    Next i
    Exit Sub
Mensaje:
    MsgBox Err.Description, vbInformation + vbCritical
End Sub

Public Sub Carga_Linea(F As Form)
Dim Rs1 As New ADODB.Recordset
  Set Rs1 = CLS_Comando.Ejec_Comando_1("sp_Inv_Trae_Linea", gbCodEmpresa$, "In01CodLinArt", "*")
  If Rs1.RecordCount > 0 Then
        Rs1.MoveFirst
        F.CboLinea.Clear
        While Not Rs1.EOF
           F.CboLinea.AddItem Trim$(Rs1("In01CodLinArt")) + " - " + Trim$(Rs1("In01Descripcion"))
           Rs1.MoveNext
        Wend
        Set Rs1 = Nothing
  End If
End Sub

Public Sub Carga_Clase(F As Form, WcLinea)
On Error GoTo Mio
    Dim Rs1 As New ADODB.Recordset
    Set Rs1 = CLS_Comando.Ejec_Comando_1("Spu_Inv_Trae_SubLinea", gbCodEmpresa$, "In02CodLinArt", WcLinea)
    If Rs1.RecordCount > 0 Then
        Rs1.MoveFirst
        F.CboSubLinea.Clear
        While Not Rs1.EOF
             F.CboSubLinea.AddItem Trim$(Rs1("In02CodGrupArt")) + " - " + Trim$(Rs1("In02Descripcion"))
             Rs1.MoveNext
         Wend
         Set Rs1 = Nothing
    End If
    Exit Sub
Mio:
    MsgBox Err.Description
    Exit Sub
End Sub

Public Sub BuscaLinea(F As Form, WLinea)
Dim i As Integer
   For i = 0 To F.CboLinea.ListCount - 1
      If Trim(Left(F.CboLinea.List(i), 2)) = Trim(Left(WLinea, 2)) Then
          F.CboLinea.ListIndex = (i)
          Exit For
      End If
   Next
End Sub

Public Sub BuscaSubLinea(F As Form, WSubLinea)
Dim i As Integer
   For i = 0 To F.CboSubLinea.ListCount - 1
      If Trim(Left(F.CboSubLinea.List(i), 2)) = Trim(Left(WSubLinea, 2)) Then
          F.CboSubLinea.ListIndex = (i)
          Exit For
      End If
   Next
End Sub

Public Sub Crear_TablaDetalle()
On Error GoTo Mensaje
    Set Ry_Detalle = New ADODB.Recordset
    With Ry_Detalle.Fields
        .Append "Articulo", adVarChar, 20
        .Append "Descripcion", adVarChar, 200
        .Append "Unidad", adVarChar, 100
        .Append "Cantidad", adDouble
        .Append "Almacen", adVarChar, 2
        .Append "Glosa", adVarChar, 300
    End With
    Ry_Detalle.Open
    Exit Sub
Mensaje:
    MsgBox Err.Description
End Sub

Public Sub Inserta_TablaDetalle(ByVal Campo0 As String, ByVal Campo1 As String, ByVal Campo2 As String, ByVal Campo3 As Double, ByVal Campo4 As String)
On Error GoTo Mio
    With Ry_Detalle
        .AddNew
        .Fields(0) = Campo0
        .Fields(1) = Campo1
        .Fields(2) = Campo2
        .Fields(3) = Campo3
        .Fields(4) = Campo4
        .Update
    End With
    Exit Sub
Mio:
    MsgBox Err.Description, vbInformation + vbCritical
End Sub

Public Sub Hablilita_Grilla(F As Form, xcol As Integer, Valor As Boolean)
On Error GoTo Mio
    Dim i As Integer
    For i = 0 To xcol
        F.tblDetalle.Columns(i).Locked = Valor
    Next i
    Exit Sub
Mio:
   MsgBox Err.Description
End Sub

Public Function DameDescripcionRomantex(cCodE, cCodigoBus, cFlag$) As String
    Set Cmd = CLS_Comando.Ejec_Comando_2("sp_Fac_Dame_Descripcion_Romantex", cCodE, cCodigoBus, cFlag$, "")
    DameDescripcionRomantex = aTexto(Cmd(4))
End Function

Public Sub SeleccionaItemProduccion()
End Sub

Public Sub Siguiente(FlexGridListaPersona As VSFlexGrid)
   If (FlexGridListaPersona.row < FlexGridListaPersona.Rows - 1) Then
       FlexGridListaPersona.row = FlexGridListaPersona.row + 1
       wjCodigo = Trim(FlexGridListaPersona.TextMatrix(FlexGridListaPersona.row, 0))
   End If
End Sub

Public Sub Anterior(FlexGridListaPersona As VSFlexGrid)
   If (FlexGridListaPersona.row > 1) Then
       FlexGridListaPersona.row = FlexGridListaPersona.row - 1
       wjCodigo = Trim(FlexGridListaPersona.TextMatrix(FlexGridListaPersona.row, 1))
   End If
End Sub

Public Sub Ultimo(FlexGridListaPersona As VSFlexGrid)
   If (FlexGridListaPersona.row < FlexGridListaPersona.Rows - 1) Then
        FlexGridListaPersona.row = FlexGridListaPersona.Rows - 1
        wjCodigo = Trim(FlexGridListaPersona.TextMatrix(FlexGridListaPersona.row, 1))
   End If
End Sub

Public Sub Pintar_Check_Flex(Flex As VSFlexGrid, ctFila As Integer, ctColum As Integer, ctDesde As Integer, ctHasta As Integer)
On Error GoTo ErrRango
  Dim i As Integer, ii, intFila, intFilaP, r
  With Flex
        If .Cell(flexcpChecked, ctFila, ctColum) = flexChecked Then
            intFilaP = ctDesde
            For ii = ctDesde To ctHasta
                .Col = intFilaP
                .CellBackColor = &HFFE1C4    '&H80FF&
                intFilaP = intFilaP + 1
            Next
        Else
            intFilaP = ctDesde
            For ii = ctDesde To ctHasta
                .Col = intFilaP
                .CellBackColor = vbWhite
                intFilaP = intFilaP + 1
            Next
        End If
  End With
  Exit Sub
ErrRango:
  MsgBox Err.Description, vbInformation
End Sub

Public Sub Tecla_Dow(NroTecla As String, F As Form)
Select Case NroTecla
    Case "114"
        F.cmdNew_Click
    Case "115"
        F.cmdDelete_Click
    Case "116"
        F.cmdModify_Click
End Select
End Sub

Public Function ConsistenciaNumeroDecimal(Num As Integer) As Integer
    Select Case Num
        Case Asc("0") To Asc("9"): ConsistenciaNumeroDecimal = Num
        Case Asc("."), Asc("-"): ConsistenciaNumeroDecimal = Num
        Case 13, 27, 9, 8: ConsistenciaNumeroDecimal = Num
        Case Else: ConsistenciaNumeroDecimal = 0
    End Select
End Function

